﻿using System;

namespace Sustainalytics.ESGRatings.Primitives
{
    public class GovernanceRatingsResult : IDisposable
    {
        readonly BufferManager _manager;
        public int ComparativeGroupsCount { get; private set; }

        public GovernanceRatingsResult(BufferManager manager,int companiesCount, int indicatorsCount, int issuesCount,int comparativeGroupsCount)
        {
           
            _manager = manager;
            ComparativeGroupsCount = comparativeGroupsCount;
            CompaniesCount = companiesCount;
            IssuesCount = issuesCount;
            IndicatorsCount = indicatorsCount;
          
          
        }


        public void AllocateBuffers()
        {
            Ratings = _manager.Get<float>(CompaniesCount * IssuesCount);
            CompanyIndices = _manager.Get<int>(CompaniesCount * IssuesCount*ComparativeGroupsCount);
            Rankings = _manager.Get<int>(CompaniesCount * IssuesCount*ComparativeGroupsCount);
            Percentile = _manager.Get<float>(CompaniesCount * IssuesCount*ComparativeGroupsCount);
            GroupCounts = _manager.Get<int>(CompaniesCount * IssuesCount*ComparativeGroupsCount);
            IssuesWeightedScores = _manager.Get<float>(CompaniesCount*IssuesCount);
            Weights = _manager.Get<float>(CompaniesCount*IssuesCount);

        }



        public int IndicatorsCount { get; set; }

        public int IssuesCount { get; set; }

        public int CompaniesCount { get; set; }

        public float[] Ratings;
        public int[] CompanyIndices;
        public float[] Percentile;
        public int[] Rankings;
        public int[] GroupCounts;

        public float[] Weights;
        public float[] IssuesWeightedScores;


        private bool _disposed;
        public void Dispose()
        {
            if (_disposed)
                return;

            _disposed = true;

            if (Ratings != null)
                _manager.Release(Ratings);

            if (CompanyIndices != null)
                _manager.Release(CompanyIndices);

            Ratings = null;
            CompanyIndices = null;
            Percentile = null;
            Ratings = null;
            Rankings = null;
            Percentile = null;
            GroupCounts =null;
            IssuesWeightedScores=null;
            Weights = null;
        }


    }
}